from icfc.iic import IIC
from pynq.lib.iic import AxiIIC


def iicTest():
    dev = IIC()
    dev.init(2)  #open /dev/i2c-1
    r = dev.set(0x2c, 0, 200)
    print(r)
    dev.deinit()


def xiicAd5254():
    dict = {'phys_addr': 0xA0005000, 'addr_range': 0x1000}
    dev = AxiIIC(dict)
    data = bytes([1, 50])
    ret = dev.send(0x2c, data, 2)
    print(ret)


def xiicIna226():
    dict = {'phys_addr': 0xA0002000, 'addr_range': 0x1000}
    slave = 0x40
    dev = AxiIIC(dict)
    data = bytes([2])
    dev.send(slave, data, 1)
    ret = bytes([0, 0])
    dev.receive(slave, ret, 2)
    v = ret[0] << 8 | ret[1]
    v = v * 1.25
    print(v)

xiicIna226()